// pages/gcdetail/gcdetail.js
import {
  getIndexCatGoods
} from '../../apis/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodC: '',
    goodList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let goodC = ''
    if(options.goodc.includes('veg.png')) goodC = '蔬菜'
    if(options.goodc.includes('meet.png')) goodC = '肉'
    if(options.goodc.includes('fish.png')) goodC = '水产'
    if(options.goodc.includes('rice.png')) goodC = '大米'
    if(options.goodc.includes('egg.png')) goodC = '蛋'
    if(options.goodc.includes('best2.png')) goodC = '特产'
    if(options.goodc.includes('icon.png')) goodC = '玉米'
    if(options.goodc.includes('fruit.png')) goodC = '水果'
    if(options.goodc.includes('bird.png')) goodC = '禽类'
    if(options.goodc.includes('mmeat.png')) goodC = '畜肉'
    this.setData({
      goodC
    })
    await this.getGoods()
  },
  async getGoods() {
    const res = await getIndexCatGoods({type: this.data.goodC})
    const gList = []
    for(let i = 0; i < res.data.length; i++) {
      if(res.data[i].commodityQuantity !== 0) {
        gList.push(res.data[i])
      }
    }
    this.setData({
      goodList: gList
    })
  }
})